package com.sino.business.service;

import java.util.Iterator;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.sino.bean.Basicinfo;
import com.sino.bean.Sharepeople;
import com.sino.bean.Zjclinfo;
import com.sino.business.IZjclService;
import com.sino.dao.IBasicInfoDAO;
import com.sino.model.ZjclModel;

public class ZjclServiceImp implements IZjclService {
	private IBasicInfoDAO basicInfoDAO = null;
	/**
	 * Description ：保存附件及证明材料目录信息到数据库中
	 * 
	 * @param zjclModel ：证明材料目录基础类
	 */
	public void saveZjcl(ZjclModel zjclModel) {
		Zjclinfo[] zjcls = this.getZjclinfo(zjclModel);
		Zjclinfo zjcl;
		for(int  i = 0 ; i < 18 ; i++){
			zjcl = zjcls[i];
			this.getBasicInfoDAO().saveZjcl(zjcl);
		}
	}

	/**
	 * Description ：更新其他共有专利人信息到数据库中
	 * 
	 * @param zjclModel：证明材料目录基础类
	 */
	public void updateZjcl(ZjclModel zjclModel) {}
	/**
     * Description       	   ：根据专利Id查找附件及证明材料目录信息
     * @param zlId	     	   ：专利Id
     */
	public ZjclModel findZjcl(String zlId){
		List temp = this.getBasicInfoDAO().findZjcl(zlId);
		return this.getZjclModel(temp);
	}

	// -----------------------------数据转换
	public ZjclModel getZjclModel(List zjclInfoList) {
		ZjclModel zjclModel = new ZjclModel();
		Iterator it = zjclInfoList.iterator();
		Zjclinfo zjcl;
		int i = 1;
		while(it.hasNext()){
			zjcl = (Zjclinfo)it.next();
			try{
				BeanUtils.copyProperty(zjclModel, "id"+i, zjcl.getId());
				BeanUtils.copyProperty(zjclModel, "xh"+i, zjcl.getXh());
				BeanUtils.copyProperty(zjclModel, "zlmc"+i, zjcl.getZlmc());
				i++;
			}catch(Exception ex){
				ex.printStackTrace();
			}
		}
		return zjclModel;
	}

	public Zjclinfo[] getZjclinfo(ZjclModel zjclModel) {
		Basicinfo basicInfo = new Basicinfo();
		basicInfo.setZlid(zjclModel.getZlId());
		Zjclinfo[] zjcl = { new Zjclinfo(), new Zjclinfo(), new Zjclinfo(),
				new Zjclinfo(), new Zjclinfo(), new Zjclinfo(), new Zjclinfo(),
				new Zjclinfo(), new Zjclinfo(), new Zjclinfo(), new Zjclinfo(),
				new Zjclinfo(),new Zjclinfo(),new Zjclinfo(),new Zjclinfo(),new Zjclinfo(),new Zjclinfo(),new Zjclinfo() };
		
		zjcl[0].setId(zjclModel.getId1());
		zjcl[0].setXh(zjclModel.getXh1());
		zjcl[0].setZlmc(zjclModel.getZlmc1());
		zjcl[0].setBasicinfo(basicInfo);
		
		zjcl[1].setId(zjclModel.getId2());
		zjcl[1].setXh(zjclModel.getXh2());
		zjcl[1].setZlmc(zjclModel.getZlmc2());
		zjcl[1].setBasicinfo(basicInfo);
		
		zjcl[2].setId(zjclModel.getId3());
		zjcl[2].setXh(zjclModel.getXh3());
		zjcl[2].setZlmc(zjclModel.getZlmc3());
		zjcl[2].setBasicinfo(basicInfo);
		
		zjcl[3].setId(zjclModel.getId4());
		zjcl[3].setXh(zjclModel.getXh4());
		zjcl[3].setZlmc(zjclModel.getZlmc4());
		zjcl[3].setBasicinfo(basicInfo);
		
		zjcl[4].setId(zjclModel.getId5());
		zjcl[4].setXh(zjclModel.getXh5());
		zjcl[4].setZlmc(zjclModel.getZlmc5());
		zjcl[4].setBasicinfo(basicInfo);
		
		zjcl[5].setId(zjclModel.getId6());
		zjcl[5].setXh(zjclModel.getXh6());
		zjcl[5].setZlmc(zjclModel.getZlmc6());
		zjcl[5].setBasicinfo(basicInfo);
		
		zjcl[6].setId(zjclModel.getId7());
		zjcl[6].setXh(zjclModel.getXh7());
		zjcl[6].setZlmc(zjclModel.getZlmc7());
		zjcl[6].setBasicinfo(basicInfo);
		
		zjcl[7].setId(zjclModel.getId8());
		zjcl[7].setXh(zjclModel.getXh8());
		zjcl[7].setZlmc(zjclModel.getZlmc8());
		zjcl[7].setBasicinfo(basicInfo);
		
		zjcl[8].setId(zjclModel.getId9());
		zjcl[8].setXh(zjclModel.getXh9());
		zjcl[8].setZlmc(zjclModel.getZlmc9());
		zjcl[8].setBasicinfo(basicInfo);
		
		zjcl[9].setId(zjclModel.getId10());
		zjcl[9].setXh(zjclModel.getXh10());
		zjcl[9].setZlmc(zjclModel.getZlmc10());
		zjcl[9].setBasicinfo(basicInfo);
		
		zjcl[10].setId(zjclModel.getId11());
		zjcl[10].setXh(zjclModel.getXh11());
		zjcl[10].setZlmc(zjclModel.getZlmc11());
		zjcl[10].setBasicinfo(basicInfo);
		
		zjcl[11].setId(zjclModel.getId12());
		zjcl[11].setXh(zjclModel.getXh12());
		zjcl[11].setZlmc(zjclModel.getZlmc12());
		zjcl[11].setBasicinfo(basicInfo);
		
		zjcl[12].setId(zjclModel.getId13());
		zjcl[12].setXh(zjclModel.getXh13());
		zjcl[12].setZlmc(zjclModel.getZlmc13());
		zjcl[12].setBasicinfo(basicInfo);
		
		zjcl[13].setId(zjclModel.getId14());
		zjcl[13].setXh(zjclModel.getXh14());
		zjcl[13].setZlmc(zjclModel.getZlmc14());
		zjcl[13].setBasicinfo(basicInfo);
		
		zjcl[14].setId(zjclModel.getId15());
		zjcl[14].setXh(zjclModel.getXh15());
		zjcl[14].setZlmc(zjclModel.getZlmc15());
		zjcl[14].setBasicinfo(basicInfo);
		
		zjcl[15].setId(zjclModel.getId16());
		zjcl[15].setXh(zjclModel.getXh16());
		zjcl[15].setZlmc(zjclModel.getZlmc16());
		zjcl[15].setBasicinfo(basicInfo);
		
		zjcl[16].setId(zjclModel.getId17());
		zjcl[16].setXh(zjclModel.getXh17());
		zjcl[16].setZlmc(zjclModel.getZlmc17());
		zjcl[16].setBasicinfo(basicInfo);
		
		zjcl[17].setId(zjclModel.getId18());
		zjcl[17].setXh(zjclModel.getXh18());
		zjcl[17].setZlmc(zjclModel.getZlmc18());
		zjcl[17].setBasicinfo(basicInfo);
		
		return zjcl;
	}
	//------------------------------接口

	public IBasicInfoDAO getBasicInfoDAO() {
		return basicInfoDAO;
	}

	public void setBasicInfoDAO(IBasicInfoDAO basicInfoDAO) {
		this.basicInfoDAO = basicInfoDAO;
	}
}
